/*
**NCS log Library Procedures
**This module provide the log API for NCS 
**
**
**Copyright (C) 2016-xxxx andisat <www.andisat.com>
**
**Author: andisat
**Date:2016-1-10
**
*/
#include <stdio.h>
#include <stdarg.h>
#include "ncs_log.h"


#define STDOUT_FLAG  1
#define SYSLOG_FLAG  2
#define FILE_FLAG  3

int log_flag=STDOUT_FLAG;

int ncs_openlog(const char *progname, int option,int facility)
{
    if(log_flag == SYSLOG_FLAG)
        if(progname){
            openlog(progname,option,facility);
            return 0;
        }
    else if(log_flag == FILE_FLAG)
        return 0;
    
    return -1;
}

void ncs_log(const int facility, const char *format, ...)
{
    char buf[LOG_BUF_MAX];
    va_list args;

    va_start(args, format);
    vsnprintf(buf, sizeof(buf), format, args);
    if(log_flag == SYSLOG_FLAG)
        syslog(facility, "%s", buf);
    else if(log_flag == STDOUT_FLAG)
        printf("%s \n",buf);
    else
        ;        
    va_end(args);
}

void ncs_log_new(int severity, const char *msg)
{
     if(log_flag == SYSLOG_FLAG)
        syslog(severity, "%s", msg);
    else if(log_flag == STDOUT_FLAG)
        printf("%s \n",msg);
    else
        ;
    
    return;
}

void ncs_closelog()
{
    closelog();
}




